#pragma once
#include "ReadInBits.h"
#include "LongReadInBits.h"
using namespace std;

// Calculate the difference of bits
// unsigned int bitsStrCompare(WORD_SIZE  UpperBits1,  WORD_SIZE LowerBits1,  WORD_SIZE UpperBits2,  WORD_SIZE LowerBits2);
unsigned int bitsStrCompare(CReadInBits r1, CReadInBits r2);

// compare the last N bits only
// unsigned int bitsStrNCompare(WORD_SIZE  UpperBits1,  WORD_SIZE LowerBits1,  WORD_SIZE UpperBits2,  WORD_SIZE LowerBits2);
// count the diff of the first N base pairs.
unsigned int bitsStrNCompare(CReadInBits r1, CReadInBits r2, unsigned int N);
unsigned int bitsStrNCompare(CLongReadInBits r1, CLongReadInBits r2, unsigned int N);
// skip the first M base pair and count the diff of the following N base pair
unsigned int bitsStrMNCompare(CReadInBits r1, CReadInBits r2, unsigned int M, unsigned int N);
unsigned int bitsStrMNCompare(CLongReadInBits r1, CLongReadInBits r2, unsigned int M, unsigned int N);

inline bool isZero(WORD_SIZE w)
{
    return(w == 0);
}

inline bool isZero(const CReadInBits& r)
{
    return(r.UpperBits == 0x00 && r.LowerBits == 0x00);
}

inline bool isZero(const CLongReadInBits& r)
{
    return(isZero(r.first) && isZero(r.second));
}

// The i index start from 0
inline CReadInBits setIthBit(CReadInBits original, CReadInBits source, unsigned int i)
{
    CReadInBits mask;
    mask.LowerBits = mask.UpperBits = 0x01;
    mask = (mask << i) & source;
    CReadInBits dest = (isZero(mask)) ? original : (original | mask);
    return(dest);
}
/*
CLongReadInBits setIthBit(CLongReadInBits original, CLongReadInBits source, unsigned int i) {
}*/